package com.zzw.hj77;

import java.util.*;

/**
 * @Project: hw_java
 * @Description: 火车进站
 * @Author: zzw
 */

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static List<String> res = new ArrayList<>();

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            int[] nums = new int[n];
            Stack<Integer> stk = new Stack<>();
            for (int i = 0; i < n; i++) {
                nums[i] = in.nextInt();
            }
            helper(nums, 0, stk, "", 0);
            Collections.sort(res);
            for (String s : res) {
                System.out.println(s);
            }
        }
    }

    public static void helper(int[] nums, int i, Stack<Integer> stk, String s, int n) {
        if (n == nums.length) {
            res.add(s);
        }
        if (!stk.empty()) {
            int tmp = stk.pop();
            helper(nums, i, stk, s + tmp + " ", n + 1);
            stk.push(tmp);
        }
        if (i < nums.length) {
            stk.push(nums[i]);
            helper(nums, i + 1, stk, s, n);
            stk.pop();
        }
    }
}